﻿namespace NEnsure.Rules
{
	public abstract class BaseBusinessRule<T> : IBusinessRule
	{
		private string _errorFormat;

		public abstract string RuleKey { get; }

		public string ErrorFormat
		{
			get { return _errorFormat; }
			set { _errorFormat = value; }
		}

		public BaseBusinessRule(string defaultErrorFormat)
		{
			_errorFormat = defaultErrorFormat;
		}

		public override bool Equals(object obj)
		{
			IBusinessRule<T> other = obj as IBusinessRule<T>;

			if (other == null)
			{
				return false; 
			}

			return RuleKey == other.RuleKey;
		}

		public override int GetHashCode()
		{
			return RuleKey.GetHashCode() + typeof(T).GetHashCode();
		}
	}
}
